<?php
class ProjectModel extends CI_Model {

	var $id_project = '';
	var $cd_user = '';
	var $cd_style= '';
	var $cd_file_type = '';
	var $nm_project = '';
	var $vl_value = '';
	var $ds_description = '';
	var $nm_audience = '';
	var $vl_color = '';
	var $dt_begin = '';
	var $dt_end = '';
	var $fl_finished = '';
	var $fl_identification = '';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function save($entry)
	{
		$this->id_project = NULL;
		$this->cd_user = $this->session->userdata('id');
		$this->cd_style = $entry['segment'];
		$this->cd_file_type	= $entry['file_type'];
		$this->nm_project = $entry['project_title'];
		$this->vl_value = $entry['value'];
		$this->ds_description = $entry['description'];
		$this->nm_audience = 'NULL';
		$this->vl_color = md5($entry['color']);
		$this->dt_begin = date('Y-m-d', time());
		$this->dt_end = $entry['end_date'];
		$this->fl_finished = FALSE;
		$this->fl_identification = $entry['identify'];
	
		$this->db->insert('projects', $this);
		return $this->db->insert_id();
	}
	
	public function delete($entry)
	{	
		$this->db->delete('projects', array('id_project' => $entry['id'])); 
	}
	
	
	public function update($id, $data)
	{
		$this->db->where('id_project', $id);
		$this->db->update('projects', $data); 
	}
	
	public function get_all()
	{
		$query = $this->db->get('projects');
		return $query->result();
	}

	public function get_last_entry()
	{
		$this->db->select_max('id_project');
		$query = $this->db->get('projects');
		foreach ($query->result() as $row)
		{
			return $row->id_project;
		}
		
	}
}